package com.example.firstdemo.ui.screens.pages.addProblem.addProblemList

import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.example.firstdemo.ui.screens.pages.addProblem.addProblem.navigateToAddProblem
import com.example.firstdemo.ui.screens.pages.addProblem.addProblemDetail.navigateToAddProblemDetail
import kotlinx.serialization.Serializable


@Serializable
object AddProblem


fun NavGraphBuilder.addProblemListDestination(
    padding: PaddingValues = PaddingValues(0.dp),
    navController: NavController
) {
    composable<AddProblem>(
        enterTransition = { fadeIn() },
        exitTransition = { fadeOut() },
        popEnterTransition = { fadeIn() },
        popExitTransition = { fadeOut() }
    ) {
        val viewModel: AddProblemListViewModel = viewModel()
        val uiState = viewModel.uiState.collectAsStateWithLifecycle().value
        AddProblemListScreen(
            padding,
            uiState,
            onGetProblemList = viewModel::getProblemList,
            onGotoAdd = navController::navigateToAddProblem,
            onGotoDetail = navController::navigateToAddProblemDetail
        )
    }
}

fun NavController.navigateToAddProblemList(navOptions: NavOptions? = null) {
    navigate(AddProblem, navOptions)
}